﻿Public Class frmPhotoGeoref

    Dim strNomFichier As String = ""
    Private _strLatitude, _strLongitude, strLong, strLat, Url As String
    Private flLongitude, flLatitude As Double
    Dim NSDossier As String = "/My Documents/Photos_Georef/"  '
    Dim proprietes As ClsImageProperties
    Dim dateCourante As Date
    Dim stlong, stLat, strNomFichier2 As String
    Dim result As Boolean


    Public Property strLatitude() As String
        Get
            Return _strLatitude
        End Get
        Set(ByVal value As String)
            _strLatitude = value
            actualiserGPS()

        End Set
    End Property

    Public Property strLongitude() As String
        Get
            Return _strLongitude
        End Get
        Set(ByVal value As String)
            _strLongitude = value
            actualiserGPS()

        End Set
    End Property


    Private Sub PctPhoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PctPhoto.Click
      

        dateCourante = Date.Now
        REM recuperer les coordonnées GPS

        If _strLongitude <> Nothing And _strLatitude <> Nothing Then
            stlong = _strLongitude.Substring(0, 3)
            stLat = _strLatitude.Substring(0, 2)
            flLongitude = CDbl(stlong)
            flLatitude = CDbl(stLat)
        Else
            flLongitude = 0.0
            flLatitude = 0.0
        End If

        If (m_isFormGPSOpen = True) And (m_isGpsInterpreteurOpen = True) And flLongitude <> 0.0 And flLatitude <> 0.0 Then

            strLong = conversionAngle(lblLongitude.Text)
            strLat = conversionAngle(lblLatitude.Text)
            prise_photo()

        Else
            If MsgBox(DirectCast(My.Resources.Images.alertNoGPS, String) & " " & DirectCast(My.Resources.Images.alertContinuWithoutGPS, String), MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo, "Pocket eRelevé") = MsgBoxResult.Yes Then

                strLong = "0000"
                strLat = "0000"
                prise_photo()
            End If

        End If

    End Sub


    Private Sub actualiserGPS()

        If (m_isFormGPSOpen = True) And (m_isGpsInterpreteurOpen = True) And (_strLongitude <> "0") And (_strLongitude <> "") And (_strLongitude <> Nothing) And (_strLongitude <> Nothing) Then

            lblLatitude.Text = _strLatitude
            lblLongitude.Text = _strLongitude

        Else

            lblLatitude.Text = Nothing
            lblLongitude.Text = Nothing

        End If
    End Sub

    Private Sub frmPhotoGeoref_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        actualiserGPS()
    End Sub

    Private Sub prise_photo()
        strNomFichier = PrendrePhotoGeoref()
        strNomFichier2 = strNomFichier.Substring(0, strNomFichier.Length - 4)
        Url = NSDossier & strNomFichier2 & "_ref.nsml"
        proprietes = New ClsImageProperties(dateCourante, strNomFichier, strLat, strLong)
        result = proprietes.Save(Url)
    End Sub
   

    Private Sub btnMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMenu.Click
        FormMain.Show()
        Me.Hide()
    End Sub

    Private Sub btnDataShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataShow.Click
        frmDataChoix.CreateObservationTable()
        frmDataObsTable.Show()
    End Sub

    Private Sub btnRetour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetour.Click
        frmEntryChoixTypeObs.Show()
        Me.Hide()
    End Sub

   
End Class